package com.yunkeji.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunkeji.common.core.domain.PageQuery;
import com.yunkeji.common.core.page.TableDataInfo;
import com.yunkeji.dao.domain.LikeWallDetail;
import com.yunkeji.dao.mapper.LikeWallDetailMapper;
import com.yunkeji.dao.vo.LikeWallDetailVo;
import com.yunkeji.system.domain.bo.LikeWallDetailBo;
import com.yunkeji.system.service.ILikeWallDetailService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 贴贴墙-详情(备用)Service业务层处理
 *
 * @author zhang
 * @date 2024-07-10
 */
@RequiredArgsConstructor
@Service
public class LikeWallDetailServiceImpl implements ILikeWallDetailService {

    private final LikeWallDetailMapper baseMapper;

    /** 查询贴贴墙-详情(备用) */
    @Override
    public LikeWallDetailVo queryById(Long userId) {
        return baseMapper.selectVoById(userId);
    }

    /** 查询贴贴墙-详情(备用)列表 */
    @Override
    public TableDataInfo<LikeWallDetailVo> queryPageList(LikeWallDetailBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<LikeWallDetail> lqw = buildQueryWrapper(bo);
        Page<LikeWallDetailVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /** 查询贴贴墙-详情(备用)列表 */
    @Override
    public List<LikeWallDetailVo> queryList(LikeWallDetailBo bo) {
        LambdaQueryWrapper<LikeWallDetail> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<LikeWallDetail> buildQueryWrapper(LikeWallDetailBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<LikeWallDetail> lqw = Wrappers.lambdaQuery();
        return lqw;
    }

    /** 新增贴贴墙-详情(备用) */
    @Override
    public Boolean insertByBo(LikeWallDetailBo bo) {
        LikeWallDetail add = BeanUtil.toBean(bo, LikeWallDetail.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setUserId(add.getUserId());
        }
        return flag;
    }

    /** 修改贴贴墙-详情(备用) */
    @Override
    public Boolean updateByBo(LikeWallDetailBo bo) {
        LikeWallDetail update = BeanUtil.toBean(bo, LikeWallDetail.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /** 保存前的数据校验 */
    private void validEntityBeforeSave(LikeWallDetail entity) {
        // TODO 做一些数据校验,如唯一约束
    }

    /** 批量删除贴贴墙-详情(备用) */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if (isValid) {
            // TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
